<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";

	request.setAttribute("path", path);
%>

<!DOCTYPE html>
<html>
<head>
<base href="<%=basePath%>">

<title>My JSP 'doglist.jsp' starting page</title>

<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<script type="text/javascript" src="${path}/js/jquery-1.12.3.js"></script>
<script type="text/javascript" src="${path}/js/bootstrap.js"></script>
<link rel="stylesheet" href="${path}/css/bootstrap4.css" />
<link rel="stylesheet" href="${path}/js2/fileinput.css" />
<script type="text/javascript" src="${path}/js2/fileinput.js"></script>
<script type="text/javascript" src="${path}/js2/fileinput_locale_zh.js"></script>
<style type="text/css">
body {
	font-family: "微软雅黑";
	background: url(${path}/picture/background2.jpg);
}

.a-change {
	color: #FFFFFF;
}

.btn-default-change {
	background-color: black !important;
	color: white !important;
}

.btn-default-background {
	background: url(${path}/picture/background2.jpg);
}

	.shadow{
			display: none;
		}
</style>

<script type="text/javascript">
function selectName(){
$("#form2").submit();

}
</script>

<script type="text/javascript">
function selectId(id){
 $.ajax({
 
	type : "post",
			dataType : "json",
			url : "${path}/dog/Cariadd.html",
			data : {
				"did" : id
			},
			success : function(data) {
				var a = data;
				if (a == 0) {
					alert("已添加进购物车");
				} else if (a == 1) {
					alert("请用户先登录");
					window.location.href = "${path}/page/dog/dog.jsp";
				} else if (a == 2) {
					alert("请不要重复添加");
				} else {

				}
			},
			error : function(data) {

			}

		});
	}
</script>

<script>
	function save() {
		$.ajax({
			type : "post",
			url : "${path}/dog/dogregister.html",
			cache : false,
			data : new FormData($("#form1")[0]),
			processData : false,
			contentType : false,
			success : function(data) {
				var a = data;
				if (a == 0) {
					/*       $("#remove2").click();
					      $("#dtype").val("");
					      $("#dname").val("");
					      $("#dage").val("");
					      $("#dprice").val("");
					      $("#ds").val("");
					      $("#dstatus").val(""); */
					alert("注册成功");
					window.location.reload();
				} else {
					alert("图片名已存在！请重新选取！");
					window.location.reload();
				}

			},
			error : function(data) {
			}

		})

	}
</script>

<script type="text/javascript">
   function ChangeDstatusUp(a){
   var r=confirm("确认上架?");
   if(r==true){
     $.ajax({
   type:"post",
   dataType:"json",
   url:"${path}/dog/ChangeDstatus.html",
   data:{
   "did":a,
   "dstatus":"上架"
   },
   success:function(data){
   alert("上架成功");
   window.location.reload();
   
   },
   error:function(data){
   
   }
   
   
   });
   
   }
 
   
   }
   
   
     function ChangeDstatusDown(a){
   var r=confirm("确认下架?");
   if(r==true){
    $.ajax({
   type:"post",
   dataType:"json",
   url:"${path}/dog/ChangeDstatus.html",
   data:{
   "did":a,
   "dstatus":"下架"
   },
   success:function(data){
   alert("下架成功");
   window.location.reload();
   
   },
   error:function(data){
   
   }
   
   
   });
   }
   
   
   
   }
 
 

</script>



</head>

<body>
	<!--
        	作者：531680280@qq.com
        	时间：2016-05-10
        	描述：狗狗狗注册modal
        -->
	<form id="form1" method="post" enctype="multipart/form-data">
		<div class="modal fade in" id="modalRE" data-backdrop="static">
			<div class="modal-dialog">
				<div class="modal-content" style="width: 700px;">
					<div class="modal-header">
						<button type="button" class="close" data-dismiss="modal">&times;</button>
					</div>
					<div class="modal-body" style="padding: 20px;">

						<div class="form-group" style="margin-top: 20px;">
							<div class="input-group">
								<span class="input-group-addon">狗类：</span> 
								
								<!-- <input id="dtype"
									name="dtype" type="text" class="form-control"
									style="width: 250px;" />  -->
									<select id="dtype" name="dtype" style="width: 250px;" class="form-control" >
									
									<c:forEach var="obj"  items="${list}">
									 <option value="${obj.dtypeid}">${obj.dtypename}</option> 
									</c:forEach>
									
									</select>
									
									<span class="input-group-addon"
									style="margin-left:10px ;">狗名：</span> <input id="dname"
									name="dname" type="text" class="form-control"
									style="width: 260px;" />
							</div>
						</div>
						<div class="form-group" style="margin-top: 20px;">
							<div class="input-group">
								<span class="input-group-addon">狗龄：</span> <input id="dage"
									name="dage" type="text" class="form-control"
									style="width: 250px;" /> <span class="input-group-addon"
									style="margin-left: 5px;">价格：</span> <input id="dprice"
									name="dprice" type="text" class="form-control"
									style="width: 95px;" /> <span class="input-group-addon"
									style="margin-left: 5px;">状态：</span> <select id="dstatus"
									name="dstatus" class="form-control" style="width: 95px;"  >
									<option>观赏</option>
									<option>上架</option>
									<option>下架</option>
								</select>
							</div>
						</div>
						<div class="form-group" style="margin-top: 20px;">

							<div class="input-group">
								<span class="input-group-addon" style="width: 66px;">描述</span>
								<textarea id="ds" name="ds" class="form-control"
									style="width: 590px;" rows="3"></textarea>
							</div>

						</div>
						<div>
							<!-- <input id="file-1" type="file" class="file"
								data-preview-file-type="text" name="uploadfile"> -->

							<input name="uploadfile" id="file-5" class="file" type="file"
								multiple data-preview-file-type="any" data-upload-url="#"
								data-preview-file-icon="">


						</div>

					</div>

					<div class="modal-footer">
						<div class="btn-group">
							<button type="button" class="btn btn-default-change"
								onclick="save()">保存</button>
							<!-- <input type="submit" class="btn btn-default-change"  value="保存"/> -->
							<button type="button" class="btn btn-default"
								data-dismiss="modal">取消</button>
						</div>
					</div>

				</div>

			</div>

		</div>

	</form>

	<div>
		<nav class="navbar navbar-inverse navbar-fixed-top"
			style="height: 86px;">
			<div class="container">
				<div class="row">
					<div class="navbar-header">
						<span class="navbar-brand"><a
							href="${path}/page/dog/dog.jsp"><img
								src="${path}/picture/dog.jpg" width="70px" height="60px">
						</a> </span>
					</div>
					<div>
						<ul class="nav navbar-nav navbar-left"
							style="font-size: 20px;margin-top: 20px;margin-left: 70px;">
							<li class="dropdown"><a data-toggle="dropdown"
								class="dropdown-toggle ">&nbsp;&nbsp;&nbsp;狗狗类别&nbsp;&nbsp;&nbsp;<span
									class="caret" style="width: 10px;height: 4px;"></span> </a>
								<ul class="dropdown-menu">
								<c:forEach var="obj" items="${list}">
								<li><a href="${path}/dog/selectDog.html?dtypeid=${obj.dtypeid}">${obj.dtypename}</a></li>
								</c:forEach>
									
									
								</ul>
							</li>

						</ul>
					</div>
					<div>
						<ul class="nav navbar-nav navbar-left"
							style="font-size: 20px;margin-top: 20px;margin-left: 80px;">
							<li><a data-toggle="modal" data-target="#modalRE">狗狗注册</a></li>
						</ul>
					</div>
					<div>
						<form id="form2" class="navbar-form navbar-right" style="margin-top: 28px;"  action="${path}/dog/selectDog.html"  method="post">
							<div class="form-group">
								<div class="input-group">
									<input id="selectDname" type="text" class="form-control" name="dname"
										placeholder="查询狗狗名字...." /> <span class="input-group-addon"><a
										class="glyphicon glyphicon-search a-change" onclick="selectName()"></a> </span>
								</div>

							</div>
						</form>

					</div>
				</div>
			</div>
		</nav>
	</div>

	<div style="margin-top: 86px;">

		<table id="table1" class="table table-condensed table-bordered"
			style="color: white;width: 80%;margin-left: 10%;table-layout: fixed;margin-top: 180px;">

			<c:forEach var="dog" items="${obj.data}">
				<tbody>
					<tr style="height: 240px;">
						<td
							style="width: 27%;word-wrap: break-word;line-height: 2em;border-color: #000000;border-width: 5px;">
							<div>

								<img src="${path}/dog/show.html?img=${dog.dimg}"
									style="width: 260px;height: 190px;" />
							</div>
							<div style="margin-top: 10px;margin-left: 60px;">
								<h4>
									<span style="margin-left: 25px;">${dog.dname}</span><span
										style="margin-left: 25px;">${dog.dage}</span>
								</h4>

							</div>

							<div class="btn-group" style="margin-left: 57px;">
							<c:if test="${dog.dstatus=='观赏'}">
							<button type="button" class="btn btn-default-background disabled" >&nbsp;&nbsp;上架&nbsp;&nbsp;</button>
							<button type="button" class="btn btn-default-background disabled">&nbsp;&nbsp;下架&nbsp;&nbsp;</button>
							</c:if>
							<c:if test="${dog.dstatus=='下架'}">
							<button type="button" class="btn btn-default-background " onclick="ChangeDstatusUp('${dog.did}')">&nbsp;&nbsp;上架&nbsp;&nbsp;</button>
							<button type="button" class="btn btn-default-background disabled">&nbsp;&nbsp;下架&nbsp;&nbsp;</button>
							</c:if>
							<c:if test="${dog.dstatus=='上架'}">
							<button type="button" class="btn btn-default-background disabled" >&nbsp;&nbsp;上架&nbsp;&nbsp;</button>
							<button type="button" class="btn btn-default-background " onclick="ChangeDstatusDown('${dog.did}')">&nbsp;&nbsp;下架&nbsp;&nbsp;</button>
							</c:if>
								
							</div>
						</td>
						<td
							style="width: 63%;word-wrap: break-word;text-indent: 30px;line-height: 3em;border-color: #000000;border-width: 5px;"><span>${dog.ds}</span>
						</td>
						<td
							style="word-wrap: break-word;border-color: #000000;border-width: 5px;">
                             <c:if test="${dog.dstatus=='观赏'}">
                             	<span class="glyphicon glyphicon-eye-close btn-lg"
							style="margin-top: 120px;margin-left: 20px;"></span>
                             </c:if>
                              <c:if test="${dog.dstatus=='上架'}">
                             	<a  class="glyphicon glyphicon-ok btn-lg a-change"
							style="margin-top: 120px;margin-left: 20px;" onclick="selectId('${dog.did}')"></a>
                             </c:if>
                              <c:if test="${dog.dstatus=='下架'}">
                             	<span class="glyphicon glyphicon-off btn-lg"
							style="margin-top: 120px;margin-left: 20px;"  ></span>
                             </c:if>
						
						</td>

					</tr>

				</tbody>
			</c:forEach>

		</table>

	</div>

	<div style="text-align: center;">
<%-- 	    <% 
	       PageObj obj = request.getAttribute("xxxx");
	       String  s = obj.getXXX();
	    %>
	    <%=s%> --%>
		<ul class="pagination pagination-lg">
		<c:if test="${obj.hasPreviousPage==true}">
		<li><a  href="${path}/dog/selectDog.html?pageNo=${obj.currentPageNo-1}&dname=${dname}&dtypeid=${dtypeid}">&laquo;</a></li>
		</c:if>
			 <c:forEach var="index"  begin="1" end="${obj.totalPageCount}">
			<li><a  href="${path}/dog/selectDog.html?pageNo=${index}&dname=${dname}&dtypeid=${dtypeid}">${index}</a></li>
			</c:forEach> 
			<c:if test="${obj.hasNextPage==true}">
			<li><a href="${path}/dog/selectDog.html?pageNo=${obj.currentPageNo+1}&dname=${dname}&dtypeid=${dtypeid}">&raquo;</a></li>
			</c:if>
			
			
			

		</ul>
	</div>
	
	<script type="text/javascript">
		$('#file-5').fileinput({
			language : 'zh', //设置语言
			browseLabel : '选择',
			allowedFileTypes : [ 'image', 'html', 'text', 'objects' ],
			allowedPreviewTypes : [ 'image' ],
			maxFileCount : 5,
			//enctype: 'multipart/form-data',

			msgFilesTooMany : "选择上传的文件数量({n}) 超过允许的最大数值{m}！"
		});
	</script>
</body>
</html>
